home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Serial / c / NZPWOnRec
Text File  |  1995-07-08  |  2KB  |  65 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Serial.c.NZPWOnRec
  12.     Author:  Copyright © 1993 Jason Howat
  13.     Version: 1.00 (21 Nov 1993)
  14.     Purpose: Provide a handler to modify a pollword on reception of a
  15.              character on the serial port.
  16. */
  17.  
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #include "DeskLib:Core.h"
  22. #include "DeskLib:SWI.h"
  23. #include "DeskLib:Error.h"
  24. #include "DeskLib:Serial.h"
  25.  
  26.  
  27. static unsigned *serial__RMAblock = NULL;
  28. static void *serial__pollword = NULL;
  29. static const unsigned serial__insvcode[] = {0xe92d4002,
  30.                                             0xe3c11102,
  31.                                             0xe3510001,
  32.                                             0x059f1004,
  33.                                             0x058c1000,
  34.                                             0xe8fd8002};
  35.  
  36. void Serial__NZPWORRemove(void);
  37.  
  38.  
  39. void Serial_NonZeroPollWordOnReceive(int pollword_value,
  40.                                           void *pollword)
  41. {
  42.   Error_CheckFatal(SWI(4,3, SWI_OS_Module + XOS_Bit, 6, 0, 0, 32,
  43.                                       /* TO */ NULL, NULL, &serial__RMAblock));
  44.  
  45.   if(pollword_value == 0)
  46.     pollword_value = 1;
  47.  
  48.   memcpy(serial__RMAblock, serial__insvcode, 24);
  49.   serial__RMAblock[6] = pollword_value;
  50.  
  51.   Error_CheckFatal(SWI(3,0, SWI_OS_Claim + SWI_XOS_Bit, 0x14, serial__RMAblock,
  52.                                                               pollword));
  53.   serial__pollword = pollword;
  54.  
  55.   atexit(Serial__NZPWORRemove);
  56. }
  57.  
  58. void Serial__NZPWORRemove(void)
  59. {
  60.   Error_CheckFatal(SWI(3,0, SWI_OS_Release + SWI_XOS_Bit,
  61.                                      0x14, serial__RMAblock, serial__pollword));
  62.   Error_CheckFatal(SWI(3,0, SWI_OS_Module + SWI_XOS_Bit, 7, 0,
  63.                                                              serial__RMAblock));
  64. }
  65.